package org.yxt.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.yxt.springcloud.entities.CommonResult;
import org.yxt.springcloud.sentinel.blockhandler.GlobalBlockHandler;
import org.yxt.springcloud.service.SentinelPaymentService;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "consumer")
public class ConsumerController {

    @Resource
    private SentinelPaymentService paymentService;

    /**
     * 服务降级 服务配置持久化
     *
     * @return
     */
    @GetMapping(value = "sentinel/config/storage")
    @SentinelResource(
            value = "sentinelConfigStorage",
            blockHandlerClass = {GlobalBlockHandler.class},
            blockHandler = "defaultBlockHandler"
    )
    public CommonResult fallback() {
        return paymentService.getFallBackVal(1);
    }
}
